--[[
  新手引导
  https://helpdoc.touchsprite.com/dev_docs/17/23.html
]]


local GNG_table = {
  title = '新手引导-点击-auto - 1',
  multi_color = {
      color = 0x92522a,
      posandcolors = "-4|2|0xa96237,-6|20|0x994d2f,0|34|0x944b2f,32|44|0x9f6a4b,38|41|0x984a29,39|36|0xc9734d,58|37|0x946045,59|39|0x966546",
  }
}

local GNG_table2 = {
  title = '新手引导-点击-auto - 2',
  multi_color = {
      color = 0xc5794e,
      posandcolors = "5|-6|0xce8a57,10|-3|0xce956e,25|19|0xc99162,34|31|0xc48e68,37|36|0xcc956a,38|38|0xc8916a,47|41|0xc8603a,62|28|0xc28b61,65|33|0xc38c65,66|35|0xc6946a"
  }
}

local GNG_table3 = {
  title = '新手引导-点击-auto - 3', -- 手指向上
  multi_color = {
      color = 0xffffff,
      posandcolors = "-5|11|0xffffff,7|2|0x5b2315,2|8|0x571f0f,5|31|0x551d11,36|34|0x552418,21|33|0xf0a16a,32|90|0x5a2113,17|90|0x5b3322,12|115|0x592c1a,64|115|0x5d3020,78|82|0x531b0f,105|80|0x552218,134|98|0x5e3420,137|69|0x5d3322,97|42|0x593221,70|40|0x54281b,70|61|0xf4b881,100|111|0x4af7c0"
  }
}

local function GNG_loop(table)
  local ctn = 0
  local x1,y1,x2,y2 = 0,0,0,0
  local w,h = width,height

  for i = 0, 2 do
    init(i)
    if i == 0 then
        -- RxToast("init方向为0")
        x1,y1,x2,y2 = 0,0,w-1,h-1
    elseif i == 1 then
        -- RxToast("init方向为1")
        x1,y1,x2,y2 = 0,0,h-1,w-1
    else
        -- RxToast("init方向为2")
        x1,y1,x2,y2 = 0,0,h-1,w-1
    end
    -- mSleep(10)
    for var = 1, 8 do
      keepScreen(true);
      x,y = findMultiColorInRegionFuzzy(
        table.multi_color.color,
        table.multi_color.posandcolors,
        92, x1, y1, x2, y2,  { orient = var })
      if x ~= -1 and y ~= -1 then   --如果在指定区域找到某点符合条件
        rtn = 1
        RxLog('.....GameNoviceGuidance '..table.title..' 方向 i='..i..' orient='..var)
        RxToast(table.title..' 方向 i='..i..' orient='..var)
        randomTap(x + 10, y + 5, 20, sysInit.touchUI, 1, 1000) -- 随机点击
        keepScreen(false);
        break;   --并跳出循环
      end
    end
    if ctn == 1 then
      break
    end
  end

  keepScreen(false);
  if ctn == 1 then
    mSleep(1000)
  end
  init(sysInit.rotate)
  mSleep(10)
  return ctn
end



function GameNoviceGuidance()
  if sysInit.appGuidace == 0 then return false end -- 全局控制是否开启 新手引导
  local ctn = 0
  ctn = GNG_loop(GNG_table)

  if ctn == 0 then
    ctn = GNG_loop(GNG_table2)
  end

  if ctn == 0 then
    ctn = GNG_loop(GNG_table3)
  end

  -- ctn = RxTouchWithColor(Color_game_novice_guidance) -- 新手引导
  -- if ctn == 1 then return true end

  -- ctn = RxTouchWithColor(Color_game_novice_guidance2) -- 新手引导
  -- if ctn == 1 then return true end

  -- ctn = RxTouchWithColor(Color_game_novice_guidance3) -- 新手引导 - 招募
  -- if ctn == 1 then return true end
  -- ctn = RxTouchWithColor(Color_game_novice_guidance3_2) -- 新手引导 - 招募
  -- if ctn == 1 then return true end

  -- ctn = RxTouchWithColor(Color_game_novice_guidance4) -- 新手引导 - 返回
  -- if ctn == 1 then return true end

  -- ctn = RxTouchWithColor(Color_game_novice_guidance5) -- 新手引导 - 征战
  -- if ctn == 1 then return true end

  -- ctn = RxTouchWithColor(Color_game_goto_check) -- 底部-中心 前往查看
  -- if ctn == 1 then return true end
  return ctn
end